/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.firstpart.pandian.mapper.CheckstockareaMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.firstpart.pandian.mapper;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.firstpart.pandian.entity.Checkstockarea;
import com.yonyou.ucf.mdf.app.isvdxq.secondpart.model.CheckAreaBean;
import java.sql.Types;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class CheckstockareaMapperImpl {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;

    public List<Checkstockarea> GetCheckStockAreaByCheckId(String checkId, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_checkstockarea where dxq_checkstock_id = ? and ytenant_id=? and dr=0\n";
        parameter.addParam(checkId);
		parameter.addParam(tenant_id);

        ResultSetProcessor processor = new AutoBeanListProcessor(new Checkstockarea());
        return (List<Checkstockarea>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }


    public int UpdateareaStatusByIds(List<String> checkAreaIDs, String modifier, String iStatus, String tenant_id) throws Exception {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" update dxq_checkstockarea set iStatus=?,modifier=?,modify_time=now() where `dr`=0 ");
		parameter.addParam(iStatus);
		parameter.addParam(modifier);
		if (CollectionUtil.isNotEmpty(checkAreaIDs)) {
			sqlBuilder.append(" and id in ( ");
			String separator0 = " , ";
			for (int index = 0; index < checkAreaIDs.size(); index++) {
				String item = checkAreaIDs.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < checkAreaIDs.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}else{
			sqlBuilder.append(" and id in ( '' ) ");
		}
		sqlBuilder.append(" and ytenant_id=?; ");
		parameter.addParam(tenant_id);

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }


    public String SelAreaByid(String checkAreaID, String tenant_id) throws Exception {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select iStatus from  dxq_checkstockarea  where id=? and ytenant_id=? and `dr`=0;\n";
        parameter.addParam(checkAreaID);
		parameter.addParam(tenant_id);

        ResultSetProcessor processor = new ColumnProcessor(String.class);
        return (String) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }


    public int insertBatch(List<CheckAreaBean> insertBatch) throws Exception {
		if (insertBatch == null || insertBatch.size()==0) return 0;
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into dxq_checkstockarea (`id`,`version`,`pk_temp`, `dr`,`tenant_id`,`ytenant_id`, `dxq_checkstock_id`,`locationID`,`locationName`,`locationCode`, `rfid_code`,`warehouse_name`,`warehouse_code`, `iStatus`, `modify_time`,`modifier`,`create_time`,`creator`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				CheckAreaBean item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.VARCHAR);
				parameter.addParamWithType(item.getVersion(), Types.INTEGER);
				parameter.addParamWithType(item.getPk_temp(), Types.VARCHAR);
				parameter.addParamWithType(item.getDr(), Types.SMALLINT);
				parameter.addParamWithType(item.getTenant_id(), Types.VARCHAR);
				parameter.addParamWithType(item.getTenant_id(), Types.VARCHAR);
				parameter.addParamWithType(item.getCheckId(), Types.VARCHAR);
				parameter.addParamWithType(item.getLocationID(), Types.VARCHAR);
				parameter.addParamWithType(item.getLocationName(), Types.VARCHAR);
				parameter.addParamWithType(item.getLocationCode(), Types.VARCHAR);
				parameter.addParamWithType(item.getRfid_code(), Types.VARCHAR);
				parameter.addParamWithType(item.getWarehouse_name(), Types.VARCHAR);
				parameter.addParamWithType(item.getWarehouse_code(), Types.VARCHAR);
				parameter.addParamWithType(item.getiStatus(), Types.VARCHAR);
				parameter.addParamWithType(item.getModify_time(), Types.TIMESTAMP);
				parameter.addParamWithType(item.getModifier(), Types.VARCHAR);
				parameter.addParamWithType(item.getCreate_time(), Types.TIMESTAMP);
				parameter.addParamWithType(item.getCreator(), Types.VARCHAR);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ON DUPLICATE KEY UPDATE locationID=VALUES(locationID) ,locationName=VALUES(locationName),locationCode=VALUES(locationCode),rfid_code=VALUES(rfid_code) ,warehouse_name=VALUES(warehouse_name),warehouse_code=VALUES(warehouse_code) ,iStatus=VALUES(iStatus) ,modify_time=VALUES(modify_time),modifier=VALUES(modifier) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }


    public int Insertcheckstockarea(String locationID, String locationName, String locationCode, String rfid_code, String warehouse_name, String warehouse_code, String checkId, String tenant_id, String pk_temp, String creator, String modifier, String id) throws Exception {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "INSERT INTO `dxq_checkstockarea`(`locationID`,`iStatus`,`locationName`,`locationCode`,`rfid_code`,`warehouse_name`,`warehouse_code`,`dxq_checkstock_id`,`dr`,\n" + 
			         "`tenant_id`,`ytenant_id`,`pk_temp`,`version`,`create_time`,`modify_time`,`creator`,`modifier`,`id`)                                                          \n" + 
			         "VALUES(?,'1',?,?,?,?,?,?,'0',                                                                                                                                \n" + 
			         "?,?,?,'0',now(),now(),?,?,?)                                                                                                                                 \n";
        parameter.addParam(locationID);
		parameter.addParam(locationName);
		parameter.addParam(locationCode);
		parameter.addParam(rfid_code);
		parameter.addParam(warehouse_name);
		parameter.addParam(warehouse_code);
		parameter.addParam(checkId);
		parameter.addParam(tenant_id);
		parameter.addParam(tenant_id);
		parameter.addParam(pk_temp);
		parameter.addParam(creator);
		parameter.addParam(modifier);
		parameter.addParam(id);

        
        return ymsJdbcApi.update(sql, parameter);
    }


    public int UpdateareaStatus(String checkAreaID, String modifier, String iStatus, String tenant_id) throws Exception {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxq_checkstockarea set iStatus=?,modifier=?,modify_time=now() where id=? and ytenant_id=? and `dr`=0;\n";
        parameter.addParam(iStatus);
		parameter.addParam(modifier);
		parameter.addParam(checkAreaID);
		parameter.addParam(tenant_id);

        
        return ymsJdbcApi.update(sql, parameter);
    }


    public int UpdateareaStatusBycheckid(String checkID, String modifier, String iStatus, String tenant_id) throws Exception {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxq_checkstockarea set iStatus=?,modifier=?,modify_time=now() where dxq_checkstock_id=? and ytenant_id=? and `dr`=0;\n";
        parameter.addParam(iStatus);
		parameter.addParam(modifier);
		parameter.addParam(checkID);
		parameter.addParam(tenant_id);

        
        return ymsJdbcApi.update(sql, parameter);
    }


    public String SelAreaByidsAndStatus(String checkAreaID, String tenant_id) throws Exception {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from  dxq_checkstockarea  where id=? and ytenant_id=? and `dr`=0;\n";
        parameter.addParam(checkAreaID);
		parameter.addParam(tenant_id);

        ResultSetProcessor processor = new ColumnProcessor(String.class);
        return (String) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

}
